package appx.craft.droid.uc;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;

import android.widget.ImageView;
import appx.craft.droid.R;
import appx.craft.droid.utils.Log;

public class CustomProgressDialog extends AlertDialog {
	
	private final String TAG = CustomProgressDialog.class.getCanonicalName();
	private ImageView image_progress_frame;
	public CustomProgressDialog(Context context) {
		super(context,R.style.CustomDialog);
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.d(TAG, "[ onCreate ] ");
		setContentView(R.layout.custom_progress_dialog);
		image_progress_frame = (ImageView)findViewById(R.id.image_progress_frame);
		image_progress_frame.setBackgroundResource(R.drawable.spin_animation);
	}
	
	@Override
	public void onAttachedToWindow() {
		super.onAttachedToWindow();
		// Get the background, which has been compiled to an AnimationDrawable object.
		final AnimationDrawable frameAnimation = (AnimationDrawable) image_progress_frame.getBackground();

		image_progress_frame.post(new Runnable() {
			
			@Override
			public void run() {
				
				 // Start the animation (looped playback by default).
				 frameAnimation.start();
			}
		});
	}
}
